﻿package Gameplay
{	
	import flash.display.Sprite;	
	import flash.events.Event;
	
	import GameUtils.MarkData;

	public class TrackContainer extends Sprite
	{
		private const WIDTH:int = 87;
		private const TRESHHOLD:int = 300;		
		private const XCoord:Array = new Array(1, 26, 42, 57, 73);		
		private var FStrips:Vector.<TrackStrip>;		
		private var FHeight:Number;
		private var FFirst:Mark;
		
		public function TrackContainer() 
		{
			FStrips = new Vector.<TrackStrip>();
			for(var i:int = 0; i < 5; i++)
			{
				FStrips.push(new TrackStrip(i));
			}
			mouseEnabled = mouseChildren = false;
			FHeight = new Number();
		}
		
		public function set Height(AHeight:Number):void
		{
			FHeight = AHeight;
		}
		
		public function set Data(AData:Vector.<MarkData>)
		{
			var vMark:Mark;
			
			var vData:Array = new Array();
			for (var j in AData)			
				vData.push(AData[j]);
				
			vData.sortOn(['y'], Array.NUMERIC);
			
			for(var i in vData)
			{
				vMark = new Mark();
				vMark.x = XCoord[vData[i].Index];
				if(vData[i].Index == 0)				
					vMark.width = 25;				
				vMark.y = vData[i].y;
				vMark.ParentTrack = AbstractTrack(parent);
					
				addChild(vMark);
				
				FFirst = vMark;
				FStrips[vData[i].Index].Add(vMark);
			}
						
			graphics.beginFill(0xFF0000, 0);			
			graphics.drawRect(0, 0, WIDTH, FHeight);
			graphics.endFill();
			
			y = -height;			
		}		
		
		public function Check(AID:int):Boolean
		{
			return FStrips[AID].CheckNear();
		}
		
		public function get TrashHold():int
		{
			return TRESHHOLD;
		}
		
		public function get Strips():Vector.<TrackStrip>
		{
			return FStrips;
		}
	}	
}
